import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.lcdui.*;

public final class aw extends ba
    implements br, bx, i
{

    private static final Object P = new Object();
    private static final Object Q = new Object();
    private static final o R = bh.a("loading");
    private static final o S = bh.a("loaded");
    private static final o T = bh.a("broken");
    public int a;
    public boolean b;
    public String c;
    public String d;
    public int e;
    public int f;
    public int g;
    public int h;
    public long i;
    public bl j;
    public bw k;
    public bu l;
    public ay m;
    public Hashtable n;
    public Hashtable o;
    public Hashtable p;
    public ar q;         // public ar q;
    public long r;
    public m s;
    public boolean t;
    public boolean u;
    public boolean v;
    public boolean w;
    public short x;
    public boolean y;
    public String z;
    public bw A;
    public z B;
    public bs C[];
    public cc D;
    public boolean E;
    public int F;
    private boolean U;
    private boolean V;
    private bs W;
    private static Boolean X = new Boolean(true);
    private static Boolean Y = new Boolean(false);

    public aw()
    {
        super(R);
        l = new bu();
        m = new ay(this);
        n = new Hashtable();
        o = new Hashtable();
        p = new Hashtable();
        q = new ar(1000);
        D = new cc();
        super.L = 3;
    }

    public final void a(int i1, String s1, String s2)
    {
        e = i1;
        c = s1;
        d = s2;
        j = new bl("W" + i1);
        w = s2.equals("System");
    }

    public final int g_()
    {
        return 1;
    }

    public final ba a(int i1)
    {
        return s;
    }

    public final boolean d()
    {
        return c != null && "Banner".equals(c);
    }

    public final void b(int i1) {
        if (i1 != g) {
            if (E) {
                b(((ba) (this)), F);
                E = false;
            }
        } else {
            if (!E) {
                b(((ba) (this)), -F);
                E = true;
            }
        }
    }

    private void b(ba ba1, int i1)
    {
        if(ba1 != null)
        {
            ba1.K.d += i1;
            for(int j1 = 0; j1 < ba1.g_(); j1++)
                b(ba1.a(j1), i1);

        }
    }

    public final j h()
    {
        if(s != null && ((ap) (s)).c == 1)
            return (j)s.a(0);
        else
            return null;
    }

    private void H()
    {
        if(k != null)
        {
            byte abyte0[];
            if((abyte0 = k.a()) != null && abyte0.length > 0)
                try
                {
                    l.a(new ByteArrayInputStream(abyte0));
                }
                catch(IOException _ex)
                {
                    ce.c("Corrupted theme for " + e);
                }
            k = null;
        }
    }

    public final void i() {
        if (e == 0 || "true".equals(aq.a().b("LocalScript"))) {
            try {
                InputStream inputstream = ce.d(z);
                if ((inputstream) != null) {
                    a(z.a(c, inputstream));
                    if (B != null)
                        B.l = true;
                    ce.a("Using local script " + z + " for " + e + ":" + c);
                }
            } catch (IOException ioexception) {
                ioexception.printStackTrace();
            }
        }
    }

    private void I()
    {
        if(B == null)
            i();
        if(B == null && A != null && A.d != null)
            a(((z)A.d).a(c));
    }

    public final void a(String s1, bw bw1)
    {
        z = "/" + s1;
        A = bw1;
    }

    private void a(z z1)
    {
        if(z1 != null)
        {
            z1.a = this;
            B = z1;
            bs abs[];
            (abs = C = new bs[18])[0] = z1.b("startWidget");
            abs[1] = z1.b("stopWidget");
            abs[2] = z1.b("updateWidget");
            abs[3] = z1.b("openWidget");
            abs[4] = z1.b("createElement");
            abs[5] = z1.b("actionPerformed");
            abs[8] = z1.b("getMenu");
            abs[7] = z1.b("getSoftKey");
            abs[6] = z1.b("keyAction");
            abs[9] = z1.b("timerEvent");
            abs[10] = z1.b("paint");
            abs[11] = z1.b("onSuccess");
            abs[12] = z1.b("onFailure");
            abs[13] = z1.b("messageReceived");
            abs[14] = z1.b("closeWidget");
            abs[15] = z1.b("handleMessage");
            abs[16] = z1.b("updateReceived");
            abs[17] = z1.b("parametersChanged");
        }
    }

    public final bs c(int i1)
    {
        bs abs[];
        if((abs = C) != null)
            return abs[i1];
        else
            return null;
    }

    public final void a(boolean flag)
    {
        if(t != flag)
        {
            t = flag;
            if(bt.d().e)
                bh.b().o();
        }
    }

    public final bw a(String s1)
    {
        return (bw)p.get(s1);
    }

    private ba a(String s1, String s2, o o1, Object obj){
        bb bb1;
        bs bs1 = c(4);
        if ((bs1) != null) {
            bb1 = bb.b();
            ba ba1;
            try {
                bb1.a(1, s1);
                bb1.a(2, s2);
                bb1.a(3, o1);
                bb1.a(4, obj);
                bb1.a(bs1);
                ba1 = (ba) bb1.b(0);
                bb1.c();
                return ba1;
            } catch (Exception exception) {
                bb1.c();
            }
        }
        return null;
    }

    public final void a(m m1)
    {
        m m2 = s;
        if(m1 != null)
            m1.H = this;
        s = m1;
        if(m2 != null && m2 != m1)
            m2.H = null;
        bt.d().B();
    }

    public final ap a(String s1, Object obj)
    {
        q q1;
        if((q1 = (q)o.get(s1)) != null)
            return a(q1, obj);
        else
            return new m(s1, l.a());
    }

    public final int b_(int i1)
    {
        if(q.b(0, i1))
        {
            bh.b().p();
            return 40;
        } else
        {
            return 0;
        }
    }

    public final void j()
    {
        if(!aq.a().f())
            return;
        q q1;
        if((q1 = c("alert.sound")) != null)
        {
            int i1 = 20 * (b("alert.volume", q.c(0)).e() + 1);
            ci.a(null, q1.toString(), i1);
        }
    }

    public final void a(Graphics g1, bh bh1, o o1, int i1, int j1)
    {
        String s1 = null;
        m m1;
        switch(a)
        {
        case 1: // '\001'
            int k1;
            int i2 = ((k1 = i1 / 2) * q.a) / 400;
            int j2 = o1.v;
            int l2 = k1 / 2;
            int j3 = (j1 - j2) / 2;
            g1.setColor(o1.n);
            g1.fillRect(l2, j3, k1, j2);
            g1.setColor(o1.o);
            g1.fillRect(l2 + j2 / 4, j3 + j2 / 4, i2 - j2 / 2, j2 / 2);
            return;

        case 2: // '\002'
            if((m1 = s) != null)
            {
                if(!m1.b)
                {
                    bk bk1;
                    int k2 = (bk1 = super.K).d + o1.c();
                    int i3 = bk1.e + o1.e();
                    m1.b(k2, i3, i1, j1);
                }
                bh.a(g1, bh1, m1);
                return;
            }
            // fall through

        case 0: // '\0'
        case 3: // '\003'
        case 4: // '\004'
        case 5: // '\005'
        case 6: // '\006'
            s1 = c;
            // fall through

        default:
            g1.setFont(o1.j);
            g1.setColor(o1.n);
            int l1 = (j1 - o1.j.getHeight()) / 2 + ce.d;
            g1.drawString(s1, i1 / 2, l1, 17);
            return;
        }
    }

    public final boolean a(int i1, int j1, int k1)
    {
        bt bt1;
        if(i1 == 1)
            if((bt1 = bt.d()).d == this)
                bt1.a(1, -5);
            else
                bt1.a(this);
        return true;
    }

    private m a(q q1, Object obj)
    {
        String s1 = q1.a(0).toString();
        String s2 = q1.a(1).toString();
        m m1 = new m(s1, l.a(s2));
        q q2 = q1.a(2);
        int i1 = 0;
        for(int j1 = q2.b(); i1 < j1; i1++)
            a(m1, q2.a(i1), obj);

        return m1;
    }

    private void a(m m1, q q1, Object obj) {
        String s1;
        String s2;
        o o1;
        String as1[];
        s1 = q1.a(0).toString();
        s2 = q1.a(1).toString();
        o1 = l.a(q1.a(2).toString());
        as1 = (new String[]{
                s2, q1.a(3).toString(), q1.a(4).toString(), q1.a(5).toString(), q1.a(6).toString()
        });
        if ("draw".equals(s1)) {
            bw bw1;
            if ((bw1 = a(s2)) != null) {
                as as2 = new as(o1, l.b(s2));
                m1.a(as1, as2);
            }
            return;
        }
        if ("decorate".equals(s1)) {
            m1.a(as1, new ba(o1));
        } else
            if ("script".equals(s1)) {
                ba ba1;
                if ((ba1 = a(m1.a, s2, o1, obj)) != null)
                    m1.a(as1, ba1);
            } else if ("label".equals(s1) || "text".equals(s1)) {
                String s3 = null;
                if (s2.indexOf("${") != -1) {
                    s3 = m.b(s2);
                    V = true;
                } else {
                    s3 = s2;
                }
                if (s3 != null) {
                    Object obj1 = "label".equals(s1) ? ((Object) (new az(o1, null, s3))) : ((Object) (new t(o1, s3)));
                    m1.a(as1, ((ba) (obj1)));
                }
            } else if ("spot".equals(s1)) {
                j j1 = new j(e, s2);
                m1.a(as1, j1);
            }
    }

    private void d(int i1) {
        if (a != i1) {
            a = i1;
            switch (i1) {
                case 2:
                    I = S;
                    break;
                case 4:
                case 5:
                    super.I = T;
                    r = 0L;
                    break;
                default:
                    I = R;
                    break;
            }
            bt.d().h();
        }
    }

    private void a(int i1, boolean flag)
    {
        if(flag)
        {
            q.b(i1 * 100);
            bh.b().b((br)this);
        } else
        {
            q.a(i1 * 100);
        }
        bt.d().h();
    }

    private static void a(Hashtable hashtable, String s1, Boolean boolean1)
    {
        Boolean boolean2;
        if((boolean2 = (Boolean)hashtable.get(s1)) == null || boolean2 == Y && boolean1 == X)
            boolean2 = boolean1;
        hashtable.put(s1, boolean2);
    }

    public final boolean a(Hashtable hashtable)
    {
        if(a == 2)
        {
            bw bw1;
            for(Enumeration enumeration = p.elements(); enumeration.hasMoreElements(); a(hashtable, bw1.a, X))
                bw1 = (bw)enumeration.nextElement();

            return true;
        } else
        {
            return false;
        }
    }

    private void a(q q1)
    {
        m.a(q1.b("params"));
        q q2 = q1.b("services");
        n.clear();
        int i1 = 0;
        for(int j1 = q2.b(); i1 < j1; i1++)
        {
            q q5;
            String s1 = (q5 = q2.a(i1)).a(0).toString();
            if(n.containsKey(s1))
            {
                if(n.get(s1) instanceof String)
                    n.put(s1, q.h().c(q.c((String)n.get(s1))).c(q5.a(1)));
                else
                    ((q)n.get(s1)).c(q5.a(1));
            } else
            {
                n.put(s1, q5.a(1).toString());
            }
        }

        w = n.containsKey("system");
        q q3 = q1.b("views");
        int k1 = 0;
        for(int l1 = q3.b(); k1 < l1; k1++)
        {
            q q6;
            String s2 = (q6 = q3.a(k1)).a(0).toString();
            o.put(s2, q6);
        }

        p.clear();
        q q4 = q1.b("resources");
        for(int i2 = 0; i2 < q4.b(); i2++)
        {
            q q7;
            String s3 = (q7 = q4.a(i2)).a(0).toString();
            String s4 = q7.a(1).toString();
            String s5 = q7.a(2).toString();
            bw bw1 = bw.a(s3, s5);
            p.put(s4, bw1);
        }

        r = q1.b("time").f();
        x = 0;
        if(q1.b("help").b("hasHelp").d())
            x |= 1;
        if(q1.b("help").b("showFirstTime").d())
            x |= 2;
        y = q1.b("ad").d();
    }

    private void c(Object obj)
    {
        if(obj == P)
        {
            a(1, true);
            bq.a("dabo/getwidget", q.c(e), e, obj, this, false);
            return;
        }
        if(obj == Q)
        {
            a(3, true);
            q q1 = q.h();
            Enumeration enumeration = p.elements();
            do
            {
                if(!enumeration.hasMoreElements())
                    break;
                bw bw1;
                if(!(bw1 = (bw)enumeration.nextElement()).c)
                    q1.c(q.c(ce.e(bw1.a)));
            } while(true);
            if(q1.b() > 0)
            {
                q q2;
                (q2 = q.h()).c(q.c(e));
                q2.c(q1);
                bq.a("dabo/getresources", q2, e, obj, this, false);
                return;
            }
            l();
            b(false);
        }
    }

    public final void b(Object obj, p p1)
    {
        q q1 = p1.c;
        if(obj == P)
        {
            a(2, true);
            j.a("layout", q1);
            a(q1);
            c(Q);
            return;
        }
        if(obj == Q)
        {
            a(4, true);
            for(int i1 = 0; i1 < q1.b(); i1++)
            {
                q q2;
                String s1;
                bw bw1;
                if((bw1 = bw.a(s1 = (q2 = q1.a(i1)).a(0).toString())) != null)
                    bw1.a(q2.a(2));
            }

            l();
            b(false);
        }
    }

    public final void a(Object obj, p p1)
    {
        if(obj == P || obj == Q)
            d(4);
    }

    public final boolean k()
    {
        d(1);
        q q1;
        if((q1 = j.e("layout")) == null)
        {
            d(5);
            return false;
        }
        a(q1);
        boolean flag = true;
        Enumeration enumeration = p.elements();
        do
        {
            if(!enumeration.hasMoreElements())
                break;
            bw bw1;
            if(!(bw1 = (bw)enumeration.nextElement()).c)
                flag = false;
        } while(true);
        if(!flag)
            d(5);
        return flag;
    }

    public final void a(long l1)
    {
        if(r != l1 || a != 2)
        {
            m();
            d(1);
            a(0, false);
            B = null;
            r = l1;
            J();
            c(P);
        }
    }

    private void J()
    {
        l.b();
        m.a(q.c);
        p.clear();
        n.clear();
        o.clear();
        s = null;
    }

    private static Object a(bs bs1){
        bb bb1;
        if (bs1 != null) {
            bb1 = bb.b();
            try {
                Object obj;
                bb1.a(bs1);
                obj = bb1.b(0);
                bb1.c();
                return obj;
            } catch (Exception exception) {
                bb1.c();
            }
        }
        return null;
    }

    private void K()
    {
        bw bw1;
        for(Enumeration enumeration = p.elements(); enumeration.hasMoreElements();)
            if((bw1 = (bw)enumeration.nextElement()).b.equals("lang"))
            {
                B.a(bw1.a());
                return;
            }

        if(e == 0 && ce.h != null && z != null)
        {
            String s1;
            if((s1 = ce.h.replace('-', '_')).startsWith("iw"))
                s1 = "he";
            String s2 = z.substring(0, z.length() - 2) + "l";
            InputStream inputstream;
            int i1;
            if((inputstream = ce.d(s2 + s1)) == null && (i1 = s1.indexOf('_')) != -1)
            {
                s1 = s1.substring(0, i1).toLowerCase();
                inputstream = ce.d(s2 + s1);
            }
            if(inputstream != null)
                B.a(inputstream);
        }
    }

    private void L()
    {
        String s1;
        bw bw1;
        for(Enumeration enumeration = p.keys(); enumeration.hasMoreElements(); (bw1 = (bw)p.get(s1)).a(this, s1))
            s1 = (String)enumeration.nextElement();

    }

    public final void l()
    {
        if(a == 1 || a == 3)
        {
            L();
            H();
            I();
            K();
            a(c(0));
            d(2);
            if(U)
            {
                U = false;
                bt.d().a(this, 1);
            }
        }
    }

    public final void m()
    {
        if(a == 2)
        {
            a(c(1));
            bh.b().a((Object)this);
            s = null;
            d(3);
        }
    }

    public final void n()
    {
        if(a != 6)
        {
            m();
            J();
            j.a();
            r = 0L;
            u = false;
            A = null;
            k = null;
            z = null;
            B = null;
            C = null;
            d(6);
        }
    }

    public final void a(q q1, long l1)
    {
label0:
        {
            if(l1 == -1L)
            {
                r = l1;
                return;
            }
            q q2;
            if((q2 = j.e("layout")) == null)
                return;
            boolean flag = false;
            if(l1 > r)
            {
                r = l1;
                q2.a(q.c("time"), q.a(l1));
                flag = true;
            }
            q2.a(q.c("params"), q1);
            j.a("layout", q2);
            m.a(q1);
            if(a != 2)
                break label0;
            bs bs1;
            if((bs1 = c(17)) != null)
            {
                if(!flag)
                    break label0;
                if(V)
                {
                    W = bs1;
                    u = false;
                } else
                {
                    a(bs1);
                    return;
                }
            }
            a(0L);
        }
    }

    public final aj o()
    {
        a(false);
        if(a == 2)
            return (aj)a(c(3));
        if(bt.d().a(this, false))
            U = true;
        else
        if(a == 5 || a == 4)
            bt.d().a.b("openError", this);
        return null;
    }

    public final void p()
    {
        a(c(14));
    }

    public final boolean a(Object obj)
    {
        return this == obj;
    }

    public final void a(ba ba1, int i1) {
        bs bs1;
        bb bb1;
        if (i1 == -13) {
            q q1;
            if ((q1 = m.d()) != null) {
                q q2 = q.h().c(q.c(e)).c(q1);
                bq.a("dabo/setparameters", q2, e, null, null, false);
            }
            return;
        }
        bs1 = c(5);
        if (a != 2 || bs1 == null) {
        } else {
            bb1 = bb.b();
            try {
                bb1.a(1, q());
                bb1.a(2, ba1);
                bb1.a(3, i1);
                bb1.a(bs1);
                bb1.c();
            } catch (Exception exception) {
                bb1.c();
            }
        }
    }

    public final boolean a(ba ba1, int i1, int j1)
    {
        return a(ba1, i1, j1, c(6));
    }

    public final boolean a(ba ba1, int i1, int j1, bs bs1) {
        bb bb1;
        if (a != 2 || bs1 == null) {
        } else {
            bb1 = bb.b();
            boolean flag;
            try {
                bb1.a(1, ba1);
                bb1.a(2, i1);
                bb1.a(3, j1);
                bb1.a(bs1);
                flag = bb1.a(0);
                bb1.c();
                return flag;
            } catch (Exception exception) {
                bb1.c();
            }
        }
        return false;
    }

    private boolean c(boolean flag)
    {
        if(flag || !u)
        {
            if(flag)
                v = true;
            return true;
        } else
        {
            return false;
        }
    }

    public final void b(boolean flag)
    {
        if(a == 2 && c(flag))
        {
            u = true;
            if(W != null)
            {
                a(W);
                W = null;
            }
            a(c(2));
        }
    }

    public final void a(String s1, q q1)
    {
        if(a == 2)
        {
            boolean flag = q1.b("type").toString().equals("newcontent");
            bs bs1;
            if((bs1 = c(16)) != null)
            {
                c(flag);
                bb bb1;
                (bb1 = bb.b()).a(1, s1);
                bb1.a(2, q1);
                bb1.g = bs1;
                bh.a().callSerially(bb1);
                return;
            }
            if(flag)
                b(true);
        }
    }

    public final String b(String s1)
    {
        q q1;
        if((q1 = b(s1, ((q) (null)))) != null)
            return q1.toString();
        else
            return null;
    }

    private q c(String s1)
    {
        return b(s1, ((q) (null)));
    }

    private q b(String s1, q q1)
    {
        return m.a(s1, q1);
    }

    public final Object b(String s1, Object obj) {
        bs bs1 = c(15);
        bb bb1;
        if (bs1 == null) {
            bb1 = bb.b();
            Object obj1;
            try {
                bb1.a(1, s1);
                bb1.a(2, obj);
                bb1.a(bs1);
                obj1 = bb1.b(0);
                bb1.c();
                return obj1;
            } catch (Exception exception) {
                bb1.c();
            }
        }
        return null;
    }

    public final void a(String s1, Object obj, bs bs1)
    {
        bs bs2;
        if((bs2 = c(13)) != null)
        {
            bb bb1;
            (bb1 = bb.b()).g = bs2;
            bb1.a(1, s1);
            bb1.a(2, obj);
            bb1.a(3, bs1);
            bh.a().callSerially(bb1);
        }
    }

}